package com.gopay.common.riskcontrol.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.Constants;
import com.gopay.common.constants.riskcontrol.RcDicKvpConstants;
import com.gopay.common.domain.riskcontrol.RcDicKvpConf;
import com.gopay.common.riskcontrol.dao.RcDicKvpConfQueryDAO;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by liuyong on 2017/9/4.
 */
@Repository("rcDicKvpConfQueryDAO")
public class RcDicKvpConfQueryDAOImpl extends BaseDAOImpl<RcDicKvpConf, Serializable> implements RcDicKvpConfQueryDAO{


    @Override
    public RcDicKvpConf findRcDicKvpConf(String custId, String kvpType) {
        String hql = " from RcDicKvpConf kvp where kvp.kvpType = :kvpType and kvp.kvpScope=:kvpScope and kvp.custId=:custId";

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("kvpType", kvpType);
        params.put("kvpScope",RcDicKvpConstants.KVP_SCOPE_PERSONAL_01);
        params.put("custId", custId);

        List<RcDicKvpConf> rcDicKvpConfList = findByHql(hql, params);
        if(!rcDicKvpConfList.isEmpty()){
            return rcDicKvpConfList.get(0);
        }

        return null;
    }

    @Override
    public RcDicKvpConf findDefaultDicKvpConf(String kvpType) {
        String hql = " from RcDicKvpConf kvp where kvp.kvpType = :kvpType and kvp.kvpScope=:kvpScope and kvp.custId=:custId";

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("kvpType",kvpType);
        params.put("kvpScope", RcDicKvpConstants.KVP_SCOPE_GLOBAL_00);
        params.put("custId", Constants.GOPAY_SYS_MERID);

        List<RcDicKvpConf> rcDicKvpConfList = findByHql(hql, params);
        if(!rcDicKvpConfList.isEmpty()){
            return rcDicKvpConfList.get(0);
        }

        return null;
    }
}
